<?
        require_once('../../Inc/Global.php');
        require_once('CategoryData.php');
        if(isset($_REQUEST['Submit']))
        {
                $rs = $_REQUEST;
                if(!$errors = ValidateCategory($rs))
                {
                	if(isset($_REQUEST['ID']))
                	{
                		if(!$errors = SaveCategory($rs))
                		{
                    		header("location: index.php");
                		}
                	}
                	else
                	{
                		if(!$errors = AddCategory($rs))
                  		{
                    		header("location: index.php");
                		}
                		
                	}
                }
               
        }else{
        		if(isset($_REQUEST['ID']))
        		{
                	$rs = GetCategory($_REQUEST['ID']);
        		}
        		else
        		{
        			$rs = NewCategory();
        			# Create a blank associative array -> set it up this way for error handling
        		}
        }
?>
<!DOCTYPE html>
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Create/Edit Category: <?=$rs['First_Name']?> <?=$rs['Last_Name']?></title>
        <link rel="stylesheet" type="text/css" href="../Main.css" />
</head>
<body>
        <p>This is the create/add Category screen.</p>
        
        <form method="post">
                        <div>
                                <label>ID:</label>
                                <?=$rs['ID']?>
                        </div>
                        <br />
                        <div>
                                <label for="Name">Category Name:</label>
                                <input  type="text" name="Namee" id="Name"
                                                class="<? if(isset($errors['Name'])){ ?>error<? } ?>"
                                                value="<?=$rs['Name']?>" />
                                                <? if(isset($errors['Name'])){ ?>
                                                        <span class="error"><?=$errors['Name']?></span>
                                                <? } ?>
                        </div>
                        <div>
                                <label>Creation Date:</label>
                                <?=$rs['Created_at']?>
                        </div>
                        <br />
                        <div>
                                <label>Last Updated At:</label>
                                <?=$rs['Updated_at']?>
                        </div>
                        <br />
                        <input type="submit" name="Submit" value="Submit" />
                        <input type="button" value="Cancel" onclick="window.location.href='http://cs.newpaltz.edu/~N00001387/WebClass/DatabaseProject/CategoriesMgmt/'" />
        				<br />
     					<input type="button" value="Go To Home Screen" onclick="window.location.href='http://cs.newpaltz.edu/~N00001387/WebClass/DatabaseProject/'" />
        </form>
</body>
</html>

